package lab9;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

public class RequestWorker implements Runnable
{
	private InputStreamReader in;
	private OutputStream out;
	private HttpServer server;
	private String hi = "Doug Sweeney was here! Hi, from Cedar Rapids Iowa.\r\n";
	private Socket socket;
	
	public RequestWorker(Socket socket, HttpServer server) throws IOException
	{
		in = new InputStreamReader(socket.getInputStream());
		out = socket.getOutputStream();
		this.server = server;
		this.socket = socket;
	}
	
	@Override
	public void run()
	{
		try
		{
			BufferedReader reader = new BufferedReader(in);
			String line;
			
			do{
				line = reader.readLine();
				System.out.println("line =" + line);				
			}while(!line.equals(""));		
			
			out.write(hi.getBytes());

			socket.close();
			server.connectionReleased();
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
